<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/10/23 0023
 * Time: 下午 1:02
 */

class person{
    public $name;
    public $age;
    public $sex;

    private $city;

    public function __construct($name="",$sex="男",$age=22)
    {
        $this->name=$name;
        $this->sex=$sex;
        $this->age=$age;
        $this->city="北京";
        echo "构造函数：construct\r\n";
    }

    function say(){
        echo $this->name.",".$this->sex.",".$this->age."\r\n";
    }

    function __destruct()
    {
        // TODO: Implement __destruct() method.
        echo "析构函数：我是".$this->name;
    }

    function __call($name, $arguments)
    {
        // TODO: Implement __call() method.
        echo "你调用的函数".$name."不存在\r\n";
        echo "参数为：\r\n";
        print_r($arguments);
        echo "\r\n";
    }

    public static function __callStatic($name, $arguments)
    {
        // TODO: Implement __callStatic() method.
        echo "你调用的静态方法：".$name."不存在\r\n";
        echo "参数为：\r\n";
        print_r($arguments);
        echo "\r\n";
    }

    public function __get($name)
    {
        // TODO: Implement __get() method.
        echo "访问私有成员：".$name."\r\n";
        return $this->$name;
    }

    public function __set($name, $value)
    {
        // TODO: Implement __set() method.
        echo "设置私有成员的值：\r\n";
        $this->$name = $value;
    }

    public function __isset($name)
    {
        echo "调用了__isset函数\r\n";
        // TODO: Implement __isset() method.
        return isset($this->$name);
    }

    public function __unset($name)
    {
        echo "调用了____unset函数\r\n";
        // TODO: Implement __unset() method.
        unset($this->$name);

    }

    public function __sleep()
    {
        // TODO: Implement __sleep() method.
        $this->city="东京";
        $this->age=9999;
        return ['name','age'];
    }

    public function __wakeup()
    {
        // TODO: Implement __wakeup() method.
        //$this->city="贵阳";
        //$this->age=888;
    }

    public function __toString()
    {
        // TODO: Implement __toString() method.
        return "abc\r\n";
    }

    public function __invoke()
    {
        // TODO: Implement __invoke() method.
        echo "把我当成函数了吧\r\n";
    }

    public static function __set_state($an_array)
    {
        // TODO: Implement __set_state() method.

        $a = new person();
        $a->city=$an_array;
        return $a;
    }
}

//$person = new person("jack");
//$person->say();

//$person->test(123,"china");

//person::jack("bbb",888);
//echo $person->city."\r\n";
//$person->city="上海";
//echo $person->city."\r\n";

//echo "city是否存在：".isset($person->city)."\r\n";
//unset($person->city);
//echo "city是否存在：".isset($person->city)."\r\n";

//echo $a = serialize($person);
//echo "\r\n";

//var_dump(unserialize($a));


//echo $person;

//$person();
//var_export($person);

//$person2 = clone $person;
//
//$person->age=888888;
//
//print_r($person);
//echo "\r\n";
//
//print_r($person2);
//
//class Tony implements ArrayAccess,IteratorAggregate,Countable {
//    public $data;
//    public $age=22;
//    public $city="beijing";
//    public $num=10;
//
//    public function offsetExists($offset)
//    {
//        // TODO: Implement offsetExists() method.
//        return isset($this->data[$offset]);
//    }
//
//    public function offsetUnset($offset)
//    {
//        // TODO: Implement offsetUnset() method.
//        unset($this->data[$offset]);
//    }
//
//    public function offsetSet($offset, $value)
//    {
//        // TODO: Implement offsetSet() method.
//        $this->data[$offset]=$value;
//    }
//
//    public function offsetGet($offset)
//    {
//        // TODO: Implement offsetGet() method.
//
//        return $this->data[$offset];
//    }
//
//    public function getIterator()
//    {
//        // TODO: Implement getIterator() method.
//        return new ArrayIterator($this);
//    }
//
//    public function count()
//    {
//        // TODO: Implement count() method.
//        return $this->age*$this->num;
//    }
//}
//
//$data = new Tony();
//$data['name']="tony";
//$data['age']=100;
////
//////echo $data['name'];
//////echo isset($data['name']);
////unset($data['name']);
////echo "\r\n";
////echo "name exists:".isset($data['name']);
//
//foreach ($data as $k=>$v){
//
//    print_r($k);
//    print_r($v);
//}
//
//echo count($data);

interface A{
    public function show();
}
abstract class B{
    public function echo(){
        echo "china\r\n";
    }
}

class X{
    public function money(){
        echo "x money\r\n";
    }
}
class C extends B implements A{

    private $name="我是c";
    public $age=22;
    const CHINA="中国";
    const CITY="北京";
    protected $pwd=123;
    static $int=10;
    public function show()
    {
        // TODO: Implement show() method.
        echo "show\r\n";
    }
    public function __construct($a=2,$b=1,X $obj)
    {
        echo "a=".$a."\r\n";
        echo "b=".$b."\r\n";
        $obj->money();
    }
}

//$c = new C();

//$c->show();
//$c->echo();

//$reflector = new ReflectionClass("C");

//echo $reflector->name;

//echo $reflector->getConstant("CHINA");
//print_r($reflector->getConstants());

//print_r($reflector->getDefaultProperties());

//print_r($reflector->getConstructor());

//echo $reflector->getConstructor() instanceof ReflectionFunctionAbstract;

//$constructor = $reflector->getConstructor();
//print_r($constructor->name);
//print_r($constructor->getParameters());

//$args = [];
//foreach ($constructor->getParameters() as $name){
//
//    //echo $name->name."\r\n";
//    //echo $name->getType()."\r\n";
//    //echo $name->getDefaultValue()."\r\n";
//    //echo $name->isDefaultValueAvailable();
//    if ($name->isDefaultValueAvailable()){
//        //echo $name->getDefaultValue();
//        $args[] = $name->getDefaultValue();
//    }
//
//    if ($name->getType()){
//
//        $type = $name->getType();
//
//        //echo "isbuiltin:".$type->isBuiltin();
//        //echo $type->getName();
//
//        $obj = new ReflectionClass($type->getName());
//
//        $obj1 = $obj->newInstance();
//        //$obj1->money();
//
//        $args[]=$obj1;
//
//
//    }
//}
//
//
////print_r($args);
//
//$objx = $reflector->newInstanceArgs($args);
//
//
//echo key([])===0?1:2;

//print_r($a = parse_ini_file("../.env"));

//print_r(array_change_key_case($a, CASE_LOWER));